home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 December / maximum-cd-2009-12.iso / DiscContents / gimp-2.7.0-i686-setup.exe / {app} / share / gimp / 2.0 / scripts / neon-logo.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2009-08-19  |  8.9 KB  |  295 lines

  1. ; GIMP - The GNU Image Manipulation Program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ;
  4. ; This program is free software: you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation; either version 3 of the License, or
  7. ; (at your option) any later version.
  8. ;
  9. ; This program is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ; GNU General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16. ;
  17. ; NEON
  18. ; Create a text effect that simulates neon lighting
  19.  
  20. (define (apply-neon-logo-effect img
  21.                                 tube-layer
  22.                                 size
  23.                                 bg-color
  24.                                 glow-color
  25.                                 shadow)
  26.  
  27.   (define (set-pt a index x y)
  28.     (begin
  29.      (aset a (* index 2) x)
  30.      (aset a (+ (* index 2) 1) y)))
  31.  
  32.   (define (neon-spline1)
  33.     (let* ((a (cons-array 6 'byte)))
  34.       (set-pt a 0 0 0)
  35.       (set-pt a 1 127 145)
  36.       (set-pt a 2 255 255)
  37.       a))
  38.  
  39.   (define (neon-spline2)
  40.     (let* ((a (cons-array 6 'byte)))
  41.       (set-pt a 0 0 0)
  42.       (set-pt a 1 110 150)
  43.       (set-pt a 2 255 255)
  44.       a))
  45.  
  46.   (define (neon-spline3)
  47.     (let* ((a (cons-array 6 'byte)))
  48.       (set-pt a 0 0 0)
  49.       (set-pt a 1 100 185)
  50.       (set-pt a 2 255 255)
  51.       a))
  52.  
  53.   (define (neon-spline4)
  54.     (let* ((a (cons-array 8 'byte)))
  55.       (set-pt a 0 0 0)
  56.       (set-pt a 1 64 64)
  57.       (set-pt a 2 127 192)
  58.       (set-pt a 3 255 255)
  59.       a))
  60.  
  61.   (define (find-hue-offset color)
  62.     (let* (
  63.           (R (car color))
  64.           (G (cadr color))
  65.           (B (caddr color))
  66.           (max-val (max R G B))
  67.           (min-val (min R G B))
  68.           (delta (- max-val min-val))
  69.           (hue 0)
  70.           )
  71.       (if (= delta 0)
  72.           0
  73.           (begin
  74.             (cond
  75.               ((= max-val R)
  76.                (set! hue (/ (- G B) (* 1.0 delta))))
  77.               ((= max-val G)
  78.                (set! hue (+ 2 (/ (- B R) (* 1.0 delta)))))
  79.               ((= max-val B)
  80.                (set! hue (+ 4 (/ (- R G) (* 1.0 delta)))))
  81.             )
  82.             (set! hue (* hue 60))
  83.             (if (< hue 0) (set! hue (+ hue 360)))
  84.             (if (> hue 360) (set! hue (- hue 360)))
  85.             (if (> hue 180) (set! hue (- hue 360)))
  86.             hue
  87.           )
  88.       )
  89.     )
  90.   )
  91.  
  92.   (let* (
  93.         (tube-hue (find-hue-offset glow-color))
  94.         (shrink (/ size 14))
  95.         (grow (/ size 40))
  96.         (feather (/ size 5))
  97.         (feather1 (/ size 25))
  98.         (feather2 (/ size 12))
  99.         (inc-shrink (/ size 100))
  100.         (shadow-shrink (/ size 40))
  101.         (shadow-feather (/ size 20))
  102.         (shadow-offx (/ size 10))
  103.         (shadow-offy (/ size 10))
  104.         (width (car (gimp-drawable-width tube-layer)))
  105.         (height (car (gimp-drawable-height tube-layer)))
  106.         (glow-layer (car (gimp-layer-new img width height RGBA-IMAGE
  107.                      "Neon Glow" 100 NORMAL-MODE)))
  108.         (bg-layer (car (gimp-layer-new img width height RGB-IMAGE
  109.                        "Background" 100 NORMAL-MODE)))
  110.         (shadow-layer (if (= shadow TRUE)
  111.                           (car (gimp-layer-new img width height RGBA-IMAGE
  112.                            "Shadow" 100 NORMAL-MODE))
  113.                           0))
  114.         (selection 0)
  115.     (max_shrink 0)
  116.         )
  117.  
  118.     (gimp-context-push)
  119.  
  120.     ; ensure that we don't shrink selection so much
  121.     ; that we create an empty selection.
  122.     (gimp-selection-layer-alpha tube-layer)
  123.     (while (= (car (gimp-selection-is-empty img)) FALSE)
  124.     (begin
  125.       (gimp-selection-shrink img 1)
  126.           (set! max_shrink (+ max_shrink 1))
  127.           ; escape early if we know that we can perform
  128.       ; as much shrink steps as we want
  129.       (if (> max_shrink shrink)
  130.           (gimp-selection-none img))
  131.     )
  132.     )
  133.     (if (= (car (gimp-selection-is-empty img)) TRUE)
  134.     (if (> max_shrink 0)
  135.         (set! max_shrink (- max_shrink 1))))
  136.     ; clamp upper bounds to valid shrink step range
  137.     (if (> shrink max_shrink)
  138.     (set! shrink max_shrink))
  139.     (if (> inc-shrink (/ max_shrink 3))
  140.     (set! inc-shrink (/ max_shrink 3)))
  141.     (if (> shadow-shrink max_shrink)
  142.     (set! shadow-shrink max_shrink))
  143.  
  144.     (script-fu-util-image-resize-from-layer img tube-layer)
  145.     (script-fu-util-image-add-layers img glow-layer bg-layer)
  146.     (if (not (= shadow 0))
  147.         (begin
  148.           (gimp-image-add-layer img shadow-layer -1)
  149.           (gimp-edit-clear shadow-layer)))
  150.  
  151.     (gimp-context-set-background '(0 0 0))
  152.     (gimp-selection-layer-alpha tube-layer)
  153.     (set! selection (car (gimp-selection-save img)))
  154.     (gimp-selection-none img)
  155.  
  156.     (gimp-edit-clear glow-layer)
  157.     (gimp-edit-clear tube-layer)
  158.  
  159.     (gimp-context-set-background bg-color)
  160.     (gimp-edit-fill bg-layer BACKGROUND-FILL)
  161.  
  162.     (gimp-selection-load selection)
  163.     (gimp-context-set-background '(255 255 255))
  164.     (gimp-edit-fill tube-layer BACKGROUND-FILL)
  165.     (gimp-selection-shrink img shrink)
  166.     (gimp-context-set-background '(0 0 0))
  167.     (gimp-edit-fill selection BACKGROUND-FILL)
  168.     (gimp-edit-clear tube-layer)
  169.  
  170.     (gimp-selection-none img)
  171.     (if (not (= feather1 0))
  172.     (plug-in-gauss-rle RUN-NONINTERACTIVE img tube-layer feather1 TRUE TRUE))
  173.     (gimp-selection-load selection)
  174.     (if (not (= feather2 0))
  175.     (plug-in-gauss-rle RUN-NONINTERACTIVE img tube-layer feather2 TRUE TRUE))
  176.  
  177.     (gimp-selection-feather img inc-shrink)
  178.     (gimp-selection-shrink img inc-shrink)
  179.     (gimp-curves-spline tube-layer 4 6 (neon-spline1))
  180.  
  181.     (gimp-selection-load selection)
  182.     (gimp-selection-feather img inc-shrink)
  183.     (gimp-selection-shrink img (* inc-shrink 2))
  184.     (gimp-curves-spline tube-layer 4 6 (neon-spline2))
  185.  
  186.     (gimp-selection-load selection)
  187.     (gimp-selection-feather img inc-shrink)
  188.     (gimp-selection-shrink img (* inc-shrink 3))
  189.     (gimp-curves-spline tube-layer 4 6 (neon-spline3))
  190.  
  191.     (gimp-layer-set-lock-alpha tube-layer 1)
  192.     (gimp-selection-layer-alpha tube-layer)
  193.     (gimp-selection-invert img)
  194.     (gimp-context-set-background glow-color)
  195.     (gimp-edit-fill tube-layer BACKGROUND-FILL)
  196.  
  197.     (gimp-selection-none img)
  198.     (gimp-layer-set-lock-alpha tube-layer 0)
  199.     (gimp-curves-spline tube-layer 4 8 (neon-spline4))
  200.  
  201.     (gimp-selection-load selection)
  202.     (gimp-selection-grow img grow)
  203.     (gimp-selection-invert img)
  204.     (gimp-edit-clear tube-layer)
  205.     (gimp-selection-invert img)
  206.  
  207.     (gimp-selection-feather img feather)
  208.     (gimp-edit-fill glow-layer BACKGROUND-FILL)
  209.  
  210.     (if (not (= shadow 0))
  211.         (begin
  212.           (gimp-selection-load selection)
  213.           (gimp-selection-grow img grow)
  214.           (gimp-selection-shrink img shadow-shrink)
  215.           (gimp-selection-feather img shadow-feather)
  216.           (gimp-selection-translate img shadow-offx shadow-offy)
  217.           (gimp-context-set-background '(0 0 0))
  218.           (gimp-edit-fill shadow-layer BACKGROUND-FILL)))
  219.     (gimp-selection-none img)
  220.  
  221.     (gimp-drawable-set-name tube-layer "Neon Tubes")
  222.     (gimp-image-remove-channel img selection)
  223.  
  224.     (gimp-context-pop)
  225.   )
  226. )
  227.  
  228. (define (script-fu-neon-logo-alpha img
  229.                                    tube-layer
  230.                                    size
  231.                                    bg-color
  232.                                    glow-color
  233.                                    shadow)
  234.   (begin
  235.     (gimp-image-undo-group-start img)
  236.     (apply-neon-logo-effect img tube-layer (* size 5) bg-color glow-color shadow)
  237.     (gimp-image-undo-group-end img)
  238.     (gimp-displays-flush)
  239.   )
  240. )
  241.  
  242. (script-fu-register "script-fu-neon-logo-alpha"
  243.   _"N_eon..."
  244.   _"Convert the selected region (or alpha) into a neon-sign like object"
  245.   "Spencer Kimball"
  246.   "Spencer Kimball"
  247.   "1997"
  248.   "RGBA"
  249.   SF-IMAGE      "Image"                 0
  250.   SF-DRAWABLE   "Drawable"              0
  251.   SF-ADJUSTMENT _"Effect size (pixels)" '(30 1 200 1 10 0 1)
  252.   SF-COLOR      _"Background color"     "black"
  253.   SF-COLOR      _"Glow color"           '(38 211 255)
  254.   SF-TOGGLE     _"Create shadow"        FALSE
  255. )
  256.  
  257. (script-fu-menu-register "script-fu-neon-logo-alpha"
  258.                          "<Image>/Filters/Alpha to Logo")
  259.  
  260. (define (script-fu-neon-logo text
  261.                              size
  262.                              font
  263.                              bg-color
  264.                              glow-color
  265.                              shadow)
  266.   (let* (
  267.         (img (car (gimp-image-new 256 256 RGB)))
  268.         (border (/ size 4))
  269.         (tube-layer (car (gimp-text-fontname img -1 0 0 text border TRUE size PIXELS font)))
  270.         )
  271.     (gimp-image-undo-disable img)
  272.     (apply-neon-logo-effect img tube-layer size bg-color glow-color shadow)
  273.     (gimp-image-undo-enable img)
  274.     (gimp-display-new img)
  275.   )
  276. )
  277.  
  278. (script-fu-register "script-fu-neon-logo"
  279.   _"N_eon..."
  280.   _"Create a logo in the style of a neon sign"
  281.   "Spencer Kimball"
  282.   "Spencer Kimball"
  283.   "1997"
  284.   ""
  285.   SF-STRING     _"Text"               "NEON"
  286.   SF-ADJUSTMENT _"Font size (pixels)" '(150 2 1000 1 10 0 1)
  287.   SF-FONT       _"Font"               "Blippo"
  288.   SF-COLOR      _"Background color"   "black"
  289.   SF-COLOR      _"Glow color"         '(38 211 255)
  290.   SF-TOGGLE     _"Create shadow"      FALSE
  291. )
  292.  
  293. (script-fu-menu-register "script-fu-neon-logo"
  294.                          "<Image>/File/Create/Logos")
  295.